<div class="form">
<?php Yii::app()->clientScript->registerScript('form',<<<HERE
   $(document).ready(function(){
       $('#Inventory_cat').click(function(){
        $.ajax({
            url:'index.php?r=inventory/getsubcategory&cat='+$(this).val(),
            success:function(data){
                
                $('#Inventory_subcat').empty().append(data);
                
            }
        });
       });
   });
HERE
        ,  CClientScript::POS_END);?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'inventory-form',
	'enableAjaxValidation'=>false,
        'htmlOptions'=>array(
                'enctype'=>'multipart/form-data'
            )
)); ?>

	
	<?php echo $form->errorSummary($model); ?>  
        
        <div class="left-column">
            
        <div class="row short">
            
		<?php echo $form->labelEx($model,'imagepath'); ?>
              <?php echo $form->fileField($model,'file'); ?>
		
           
		<?php echo $form->error($model,'file'); ?>
	</div>
            <?php if($model->isNewRecord):?>
	<div class="row short">
		<?php echo $form->labelEx($model,'partno'); ?>
		<?php echo $form->textField($model,'partno',array('size'=>60,'maxlength'=>75)); ?>
		<?php echo $form->error($model,'partno'); ?>
	</div>
        <?php else:?>
        <div class="row short">
		<?php echo $form->labelEx($model,'partno'); ?>
            <div class='model-data'><?php echo $model->partno; ?></div>
		<?php echo $form->hiddenField($model,'partno');?>
	</div>
        <?php endif?>
        <div class="row short">
            <?php echo $form->labelEx($model,'type');?>
            <?php echo $form->dropDownList($model,'type',$model->getTypeList());?>
            <?php echo $form->error($model,'type');?>
        </div>
      <div class="row short">
		<?php echo $form->labelEx($model,'salestype'); ?>
		<?php echo $form->dropDownList($model,'salestype', Dropdowns::getList('InventorySalesType')); ?>
		<?php echo $form->error($model,'salestype'); ?>
	</div>
        <div class="row short">
		<?php echo $form->labelEx($model,'cat'); ?>
		<?php echo $form->dropDownList($model,'cat',$model->getCategoryList()); ?>
		<?php echo $form->error($model,'cat'); ?>
	</div>

	<div class="row short">
		<?php echo $form->labelEx($model,'subcat'); ?>
		<?php echo $form->dropDownList($model,'subcat',$model->getSubCategoryList()); ?>
		<?php echo $form->error($model,'subcat'); ?>
	</div>
            
        <div class="row short">
		<?php echo $form->labelEx($model,'cunits'); ?>
		<?php echo $form->textField($model,'cunits',array('size'=>2,'maxlength'=>2)); ?>
		<?php echo $form->error($model,'cunits'); ?>
	</div>    
        <div class="row short">
		<?php echo $form->labelEx($model,'lastprice'); ?>
		<?php echo $form->textField($model,'lastprice',array('value'=>  $model->lastprice, 2)); ?>
		<?php echo $form->error($model,'lastprice'); ?>
	</div>    
        <div class="row short">
		<?php echo $form->labelEx($model,'averagecost'); ?>
		<?php echo $form->textField($model,'averagecost',array('value'=>$model->averagecost,2)); ?>
		<?php echo $form->error($model,'averagecost'); ?>
	</div>    
        <div class="row short">
		<?php echo $form->labelEx($model,'baseprice'); ?>
		<?php echo $form->textField($model,'baseprice',array('value'=>$model->baseprice,2)); ?>
		<?php echo $form->error($model,'baseprice'); ?>
	</div>    
            <div class="row short">
		<?php echo $form->labelEx($model,'buysellr'); ?>
		<?php echo $form->textField($model,'buysellr'); ?>
		<?php echo $form->error($model,'buysellr'); ?>
	</div>
            
            
	<div class="row short">
		<?php echo $form->labelEx($model,'runits'); ?>
		<?php echo $form->textField($model,'runits',array('size'=>2,'maxlength'=>2)); ?>
		<?php echo $form->error($model,'runits'); ?>
	</div>
        <div class="row short">
            <?php echo $form->labelEx($model,'description');?>
            <?php echo $form->textField($model,'description');?>
            <?php echo $form->error($model,'description');?>
        </div>    
                
        </div>    
        <div class="right-column">
            <div class="row short">
              
            <?php echo $form->labelEx($model,'parttype');?>
            <?php echo $form->dropDownList($model,'parttype',$model->getPartTypeList());?>
            <?php echo $form->error($model,'parttype');?>
       
            </div>
	<div class="row short">
		<?php echo $form->labelEx($model,'markupcode'); ?>
		<?php echo $form->dropDownList($model,'markupcode',$model->getMarkupCodeList()); ?>
		<?php echo $form->error($model,'markupcode'); ?>
	</div>
            
        
        
        
	<div class="row short">
		<?php echo $form->labelEx($model,'pricea'); ?>
		<?php echo $form->textField($model,'pricea',array('value'=>$model->pricea,2)); ?>
		<?php echo $form->error($model,'pricea'); ?>
	</div>

	<div class="row short">
		<?php echo $form->labelEx($model,'priceb'); ?>
		<?php echo $form->textField($model,'priceb',array('value'=>$model->priceb,2)); ?>
		<?php echo $form->error($model,'priceb'); ?>
	</div>

	<div class="row short">
		<?php echo $form->labelEx($model,'pricec'); ?>
		<?php echo $form->textField($model,'pricec',array('value'=>$model->pricec,2)); ?>
		<?php echo $form->error($model,'pricec'); ?>
	</div>
            
	<div class="row short">
		<?php echo $form->labelEx($model,'pricebook'); ?>
		<?php echo $form->dropDownList($model,'pricebook',$model->getPriceBookList()); ?>
		<?php echo $form->error($model,'pricebook'); ?>
	</div>
            
        <div class="row short">
		<?php echo $form->labelEx($model,'salescredit'); ?>
		<?php echo $form->dropDownList($model,'salescredit',Coa::model()->getListWithDesc()); ?>
		<?php echo $form->error($model,'salescredit'); ?>
	</div>       
        <div class="row short">
		<?php echo $form->labelEx($model,'costdebit'); ?>
		<?php echo $form->dropDownList($model,'costdebit',  Coa::model()->getListWithDesc()); ?>
		<?php echo $form->error($model,'costdebit'); ?>
	</div>
    
    <div class="row short">
		<?php echo $form->labelEx($model,'inactive'); ?>
		<?php echo $form->dropDownList($model,'inactive',  array(-1=>'Inactive',0=>'Active')); ?>
		<?php echo $form->error($model,'inactive'); ?>
	</div>
	<div class="row short">
		<?php echo $form->labelEx($model,'kind'); ?>
		<?php echo $form->dropDownList($model,'kind',Inventory::getPartKinds()); ?>
		<?php echo $form->error($model,'kind'); ?>
	</div>
	<div class="row short">
		<?php echo $form->labelEx($model,'reworkable'); ?>
		<?php echo $form->checkBox($model,'reworkable', array()); ?>
		<?php echo $form->error($model,'reworkable'); ?>
	</div>	
	<div class="row short">
            <label>Re-calculate price</label>
            <input type="button" value="Re-calculate price" onclick="getPrice();"/>
            <script>
                function getPrice(){
                    $.ajax({
                        url:'index.php?r=inventory/getprice',
                        data:$('#inventory-form').serialize(),
                        type:'post',
                        timeOut:'3000',
                        success:function(data){
                            data=$.parseJSON(data);
                            $('#Inventory_pricea').val(data.pricea);
                            $('#Inventory_priceb').val(data.priceb);
                            $('#Inventory_pricec').val(data.pricec);
                        }
                    })
                }
            </script>
        </div>
            
        </div>
        <div class="clear"></div>
            

      
        
	<div class="row_buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
